package cn.xiaoqi.userapplication;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.stereotype.Component;

@Component
public class DemoEnvironmentChangeEvent implements ApplicationListener<EnvironmentChangeEvent> {

    private  final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private ConfigurableEnvironment configurableEnvironment;

    @Override
    public void onApplicationEvent(EnvironmentChangeEvent environmentChangeEvent) {
        for (String key : environmentChangeEvent.getKeys()) {
            logger.info("[onApplicationEvent][key{} 最新 value 为 {}]", key, configurableEnvironment.getProperty(key));
        }
    }

}
